﻿using UnityEngine;
using System.Collections;

public class Hack : MonoBehaviour, IInteractiveAction {

	Transform hackeableObject;
	IHackeableObject whatToHack;
	ProgressBar hackingProgressBar;
	
	// Use this for initialization
	void Start () {
		Transform pBarTransform = this.gameObject.transform.FindChild("ProgressBar");
		hackingProgressBar = (ProgressBar)pBarTransform.GetComponent(typeof(ProgressBar));
		hackingProgressBar.enabled = false;
	}
	
	// Update is called once per frame
	void Update () {
		if (hackingProgressBar.ProgressComplete()) {
			Stop();
			if (whatToHack != null) {
				whatToHack.Hack();
			}
		}
	}

	public void SetWhatToHack(Transform whatHack) {
		hackeableObject = whatHack;
		whatToHack = (IHackeableObject)whatHack.GetComponent(typeof(IHackeableObject));
	}

	public string GetActionName() {
		return "Hack (PressX)";
	}
	
	public void Execute() {
		hackingProgressBar.enabled = true;
		hackingProgressBar.SetActivateProgress(true);
	}
	
	public void Stop() {
		hackingProgressBar.enabled = false;
		hackingProgressBar.SetActivateProgress(false);

	}
}
